function Carousel(container,options){//构造函数
   this.initFlag=1;
   this.count=0;
   var ctrl=this,
       container=document.querySelector(container);
	this.options=options;
	this.wrapper=container.querySelector('.banner-wrapper');
	this.items=container.querySelectorAll('.banner-item');
	this.itemLen=this.items.length;
	this.pagination=container.querySelector('.pagination');
	this.timer=null;
    this.init(document);
}
 Carousel.prototype.screenWidth=document.body.clientWidth;
 Carousel.prototype.init=function(doc){//初始化
	if(this.initFlag){  
	   this.initFlag=null;
    }else{ 
	  console.log('尝试测试2次以上');
	  return;
	}
  // var screenWidth=document.body.clientWidth,
   var  c=this;
   var screenWidth=this.screenWidth,
       items = this.items,
	   itemLen=items.length,
	   wrapper= this.wrapper;
       wrapper.style.width=screenWidth * (itemLen+1) + 'px';
	   pagination= c.pagination,
       options=c.options;
	   timer=c.timer;
       for(var i=0;i<itemLen;i++){
	     items[i].style.width=screenWidth + 'px';
	   this.pagination.appendChild(doc.createElement('span'));//生成span元素
	   }
	   pagination.querySelector('span').className='active';//初始化 
	   wrapper.appendChild(items[0].cloneNode(true));//追加第一张的克隆节点
	   timer=setTimeout(function(){
		  c.move(options.speed);//回调函数传参数
	   },0);
	   var btns=c.pagination.querySelectorAll('span'),
	       btnLen=btns.length;
	   for(i=0;i<btnLen;i++){
		   btns[i].index=i;//自定义属性
		   btns[i].onclick=function(){
		     clearTimeout(c.timer);
			 c.wrapper.style.left='-' + c.screenWidth * this.index + 'px';
			 for(j=0;j<btnLen;j++){
			    btns[j].removeAttribute('class');
			 }
			 this.className='active';
			 c.count=this.index;
			 c.timer=setTimeout(function(){
			   c.move(options.speed);
			 },500);
		   }
	   }
  }
  Carousel.prototype.move=function(speed){
	    //console.log(this.count,this.screenWidth);
	    //console.log(speed,this.itemLen);
	   // return;
	   //count=this.count,
	  //console.log(this.pagination.querySelectorAll('span'));
	 var c=this,
		 btns=c.pagination.querySelectorAll('span');
         btnLen=btns.length;
	 if(this.count>this.itemLen-1){
		 //最后一张图执行的事件
		c.wrapper.style.left='-' + c.count * c.screenWidth + 'px';
		for(var i=0;i<btnLen;i++){
		   btns[i].removeAttribute('class');
		}
        btns[0].className='active';
		//要等待500ms的过渡效果
        setTimeout(function(){
			c.wrapper.style.transition='left 0s';
			c.count=0;
			clearTimeout(c.time);
			c.timer=setTimeout(function(){
			    c.move(speed);
			},0);
		},500); 
		 return;
	 }
	 c.wrapper.style.left='-' + c.count * c.screenWidth+ 'px';
	 if(c.count==0){//第一张
		setTimeout(function(){
			c.wrapper.style.transition='left .5s';
		},20); 
	 }
	 btns.forEach(function(element,index){
	     element.removeAttribute('class');
	 });
     btns[c.count++].className='active';//先赋值再自增
	 c.timer=setTimeout(function(){
	     c.move(speed);
	 },speed);
  }